package cn.com.startai.smartadh5.main.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import cn.com.startai.smartadh5.R;
import cn.com.startai.smartadh5.db.db.entity.PlayInfo;
import cn.com.startai.smartadh5.main.base.adapter.BaseRecyclerViewHolder;
import cn.com.startai.smartadh5.main.base.adapter.CommonRecyclerAdapter;
import cn.com.startai.smartadh5.main.base.adapter.OnItemClickListener;
import cn.com.startai.smartadh5.main.base.adapter.OnItemLongClickListener;

/**
 * @author 尹晓童
 *         邮箱：yinxtno1@yeah.net
 *         时间：2018/2/1
 *         作用：
 */

public class MusicListAdapter extends CommonRecyclerAdapter<PlayInfo, MusicListAdapter.ViewHolder> {

    public MusicListAdapter(Context context, List<PlayInfo> list) {
        super(context, list);
    }

    @Override
    protected void onBindViewHolder(ViewHolder holder, int position, PlayInfo item) {
        String musicName = item.getFileName();
        int lastPointIndex = musicName.lastIndexOf(".");
        musicName = musicName.substring(0, lastPointIndex);
        if(item.isPlaying()) {
            holder.tvMusicName.setTextColor(ContextCompat.getColor(mContext, R.color.start_ai));
        } else {
            holder.tvMusicName.setTextColor(ContextCompat.getColor(mContext, android.R.color.white));
        }

        holder.tvMusicName.setText((position + 1) + "." + musicName);
    }

    @Override
    protected ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, OnItemClickListener itemClickListener, OnItemLongClickListener itemLongClickListener) {
        return new ViewHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_music, parent, false), itemClickListener, itemLongClickListener);
    }

    class ViewHolder extends BaseRecyclerViewHolder {

        @BindView(R.id.tv_music_name)
        TextView tvMusicName;

        ViewHolder(@NonNull View v, OnItemClickListener listener,
                   OnItemLongClickListener itemLongClickListener) {
            super(v, listener, itemLongClickListener);
        }
    }
}
